package com.ty.config;

import ch.qos.logback.classic.pattern.MessageConverter;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    // 定义交换机
    @Bean
    public TopicExchange orderEventExchange() {
        return new TopicExchange("order_event_exchange");
    }

    // 定义队列
    @Bean
    public Queue stockUpdateQueue() {
        return new Queue("stock.update.queue", true); // true 表示持久化队列
    }

    // 绑定队列到交换机
    @Bean
    public Binding stockUpdateBinding(Queue stockUpdateQueue, TopicExchange orderEventExchange) {
        return BindingBuilder.bind(stockUpdateQueue)
                .to(orderEventExchange)
                .with("stock.update"); // routing key
    }
}
